<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePledgeProperties extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pledge_properties', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->string('type_key')->unsigned()->comment('Тип помещения');
            $table->foreign('type_key')->references('key')->on('types')
                ->onDelete('restrict')->onUpdate('restrict');

            $table->bigInteger('apartment_id')->unsigned()->nullable();
            $table->foreign('apartment_id')->references('id')->on('pledge_property_apartments')->onDelete('restrict');

            $table->bigInteger('house_id')->unsigned()->nullable();
            $table->foreign('house_id')->references('id')->on('pledge_property_houses')->onDelete('restrict');

            $table->bigInteger('premise_id')->unsigned()->nullable();
            $table->foreign('premise_id')->references('id')->on('pledge_property_premises')->onDelete('restrict');

            $table->bigInteger('land_id')->unsigned()->nullable();
            $table->foreign('land_id')->references('id')->on('pledge_property_lands')->onDelete('restrict');

            $table->bigInteger('building_id')->unsigned()->nullable();
            $table->foreign('building_id')->references('id')->on('pledge_property_buildings')->onDelete('restrict');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pledge_properties');
    }
}
